package com.ctcemti.mdm.project.common.excelverifyhandler;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.ctcemti.mdm.project.sys.dao.SysMaterialClassificationMapper;
import com.ctcemti.mdm.project.sys.entity.SysMaterialClassification;
import tk.mybatis.mapper.util.StringUtil;

import java.util.ArrayList;
import java.util.List;

public class ExcelVerifyHandlerForSysMaterialClassification implements IExcelVerifyHandler<SysMaterialClassification> {

    private List<String> listCode;

    private SysMaterialClassificationMapper sysMaterialClassificationMapper;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(SysMaterialClassification sysMaterialClassification) {

        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult();

        if(listCode!=null && listCode.size()>0){
            if(listCode.contains(sysMaterialClassification.getCode())){
                result.setMsg("该分类码表格中已存在");
                result.setSuccess(false);
                return result;
            }
        }
        SysMaterialClassification entity = new SysMaterialClassification();
        entity.setCode(sysMaterialClassification.getCode());
        List<SysMaterialClassification> list =  sysMaterialClassificationMapper.select(entity);
        if(!StringUtil.isEmpty(sysMaterialClassification.getCode()) && list.size()>0){
            result.setMsg("该分类码数据库中已存在");
            result.setSuccess(false);
            return result;
        }else{
            listCode.add(sysMaterialClassification.getCode());
        }
        result.setSuccess(true);
        return result;
    }

    public ExcelVerifyHandlerForSysMaterialClassification(Object object){
        this.listCode = new ArrayList<String>();
        this.sysMaterialClassificationMapper = (SysMaterialClassificationMapper) object;

    }
}
